import type { FormRule, PrimaryTableCol, SelectProps } from 'tdesign-vue-next';
import { Tag } from 'tdesign-vue-next';
import { h } from 'vue';

import { t } from '@/locales';

/**
 * 搜索表单项
 */
export const searchParams: SearchParamsProps[] = [
    {
        label: t('pages.motion.name'),
        key: 'name',
    },
    {
        label: t('pages.motion.introduction'),
        key: 'introduction',
    },
];

/**
 * 表格列
 */
export const columns: PrimaryTableCol[] = [
    {
        title: t('pages.motion.name'),
        ellipsis: true,
        align: 'center',
        colKey: 'name',
    },
    {
        title: t('pages.motion.type'),
        ellipsis: true,
        align: 'center',
        colKey: 'type',
        cell: (h, { row }) => {
            if (row.type == 0) {
                return t(`pages.motion.typeOptions.sports`);
            } else if (row.type == 1) {
                return t(`pages.motion.typeOptions.motion`);
            } else {
                return t(`pages.motion.typeOptions.sportsNew`);
            }
        },
    },
    {
        title: t('pages.motion.applicableAge'),
        ellipsis: true,
        align: 'center',
        colKey: 'applicableAge',
    },
    {
        title: t('pages.motion.beneficialPosition'),
        ellipsis: true,
        align: 'center',
        colKey: 'beneficialPosition',
    },
    {
        title: t('pages.motion.introduction'),
        ellipsis: true,
        align: 'center',
        colKey: 'introduction',
    },
    {
        title: t('pages.motion.status'),
        ellipsis: true,
        align: 'center',
        colKey: 'status',
        cell: (h, { row }) =>
            h(
                Tag,
                { theme: row.status == 1 ? 'primary' : row.status == 0 ? 'warning' : 'danger' },
                row.status == 0 ? '未发布' : row.status == 1 ? '已发布' : '已撤销',
            ),
    },
    {
        title: t('pages.motion.pushTime'),
        ellipsis: true,
        align: 'center',
        colKey: 'pushTime',
    },
    {
        title: t('pages.motion.remarks'),
        ellipsis: true,
        align: 'center',
        colKey: 'remarks',
    },
];

/**
 * 表单校验规则
 */
export const rules: Record<string, FormRule[]> = {
    name: [{ required: true, message: t('pages.motion.required.name'), type: 'error', trigger: 'blur' }],
    type: [{ required: true, message: t('pages.motion.required.type'), type: 'error', trigger: 'all' }],
    introduction: [
        { required: true, message: t('pages.motion.required.introduction'), type: 'error', trigger: 'blur' },
    ],
};

export const typeOptions: SelectProps['options'] = [
    {
        label: t(`pages.motion.typeOptions.sports`),
        value: 0,
    },
    {
        label: t(`pages.motion.typeOptions.motion`),
        value: 1,
    },
    {
        label: t(`pages.motion.typeOptions.sportsNew`),
        value: 2,
    },
];
